﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Fabs.Net.GIL;
using System.Reflection;

namespace Fabs.Net
{
    public class GCompiler
    {
        public Executable Output = new Executable();
        public GCompiler(string Name)
        {
            if (string.IsNullOrEmpty(Name))
            {
                throw new ArgumentNullException("Name");
            }
            Output.Name = Name;
        }

        internal void Parse(string Code)
        {
            Parser parser = new Parser(Code);
            parser.Parse();
            parser.Write(Output);
        }

        internal void Compile()
        {
            Output.Compile();
        }

        internal void Save()
        {
            Output.Save();
        }

        internal void Run()
        {
            if (!Output.HasEntryPoint)
            {
                throw new Exception("Başlangıç methodu tanımlanmamış");
            }

            MethodInfo method = Output.EntryPoint;
            method.Invoke(null, new object[0]);
        }
    }
}
